index.js ➔ createRouter   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 178
Code Lines 127

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 127
nc 1
nop 2
dl 0
loc 178
c 0
b 0
f 0
cc 1
rs 7

2 Functions

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ ... ➔ ??? 0 1 1
A index.js ➔ ... ➔ ???.routes.children.component.render 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import Vue from 'vue'
2
import Router from 'vue-router'
3
4
// Containers
5
import Full from '../containers/Full'
6
7
// Views
8
import Search from '../views/Search'
9
import Campaigns from '../views/Campaigns'
10
import CampaignForm from '../views/CampaignForm'
11
import Payments from '../views/Payments'
12
import PaymentForm from '../views/PaymentForm'
13
import Help from '../views/Help'
14
import Feedback from '../views/Feedback'
15
import Settings from '../views/Settings'
16
import UserForm from '../views/UserForm'
17
import UserList from '../views/UserList'
18
import Notifications from '../views/Notifications'
19
import PaymentSystems from '../views/PaymentSystems'
20
import Layout from '../views/Layout'
21
22
Vue.use(Router)
23
24
export function createRouter(base, i18n) {
25
  return new Router({
26
    mode: 'history',
27
    base: base,
28
    linkActiveClass: 'open active',
29
    scrollBehavior: () => ({ y: 0 }),
30
    routes: [
31
      {
32
        path: '/',
33
        redirect: '/campaigns',
34
        name: 'home',
35
        component: Full,
36
        meta: {
37
          label: i18n.t('labels.admin.title')
38
        },
39
        children: [
40
          {
41
            path: 'search',
42
            name: 'search',
43
            component: Search,
44
            meta: {
45
              label: i18n.t('labels.common.search')
46
            }
47
          },
48
          {
49
            path: 'campaigns',
50
            name: 'campaigns',
51
            component: Campaigns,
52
            meta: {
53
              label: i18n.t('labels.admin.campaigns.breadcrumb')
54
            }
55
          },
56
          {
57
            path: 'campaigns',
58
            component: {
59
              render(c) {
60
                return c('router-view')
61
              }
62
            },
63
            meta: {
64
              label: i18n.t('labels.admin.campaigns.title')
65
            },
66
            children: [
67
              {
68
                path: 'create',
69
                name: 'campaigns_create',
70
                component: CampaignForm,
71
                meta: {
72
                  label: i18n.t('labels.admin.campaigns.create.title')
73
                }
74
              },
75
              {
76
                path: ':id/edit',
77
                name: 'campaigns_edit',
78
                component: CampaignForm,
79
                props: true,
80
                meta: {
81
                  label: i18n.t('labels.admin.campaigns.edit.title')
82
                }
83
              }
84
            ]
85
          },
86
          {
87
            path: 'payments',
88
            name: 'payments',
89
            component: Payments,
90
            meta: {
91
              label: i18n.t('labels.admin.payments.title')
92
            }
93
          },
94
          {
95
            path: 'payments',
96
            component: {
97
              render(c) {
98
                return c('router-view')
99
              }
100
            },
101
            meta: {
102
              label: i18n.t('labels.admin.payments.title')
103
            },
104
            children: [
105
              {
106
                path: ':id/edit',
107
                name: 'payments_edit',
108
                component: PaymentForm,
109
                props: true,
110
                meta: {
111
                  label: i18n.t('labels.admin.payments.show.title')
112
                }
113
              }
114
            ]
115
          },
116
          {
117
            path: 'feedback',
118
            component: Feedback,
119
            meta: {
120
              label: i18n.t('labels.admin.feedback.title')
121
            }
122
          },
123
          {
124
            path: 'settings',
125
            component: Settings,
126
            meta: {
127
              label: i18n.t('labels.admin.settings.title')
128
            }
129
          },
130
          {
131
            path: 'layout',
132
            component: Layout,
133
            meta: {
134
              label: 'Layout'
135
            }
136
          },
137
          {
138
            path: 'paymentSystems',
139
            component: PaymentSystems,
140
            meta: {
141
              label: 'Payment systems'
142
            }
143
          },
144
          {
145
            path: 'notifications',
146
            component: Notifications,
147
            meta: {
148
              label: 'Notifications'
149
            }
150
          },
151
          {
152
            path: 'users',
153
            component: {
154
              render(c) {
155
                return c('router-view')
156
              }
157
            },
158
            meta: {
159
              label: i18n.t('labels.admin.users.title')
160
            },
161
            children: [
162
              {
163
                path: '/',
164
                name: 'users',
165
                component: UserList,
166
                meta: {
167
                  label: i18n.t('labels.admin.users.breadcrumb')
168
                }
169
              },
170
              {
171
                path: 'create',
172
                name: 'users_create',
173
                component: UserForm,
174
                meta: {
175
                  label: i18n.t('labels.admin.users.create.breadcrumb')
176
                }
177
              },
178
              {
179
                path: ':id/edit',
180
                name: 'users_edit',
181
                component: UserForm,
182
                props: true,
183
                meta: {
184
                  label: i18n.t('labels.admin.users.edit.breadcrumb')
185
                }
186
              }
187
            ]
188
          },
189
          {
190
            path: 'help',
191
            name: 'help',
192
            component: Help,
193
            meta: {
194
              label: i18n.t('labels.admin.help.title')
195
            }
196
          }
197
        ]
198
      }
199
    ]
200
  })
201
}
202